//
//  SRDeviceInfo.m
//  sr01sdkProject
//
//  Created by Linktop on 2022/5/25.
//

#import "SRDeviceInfo.h"
#import "SRDeviceInfo+description.h"
@implementation SRDeviceInfo

- (instancetype)initWithData:(NSData *)data
{
    self = [super init];
    if (self) {
        
        if (data.length < 20) {
            return  self;
        }
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        
        uint8_t color = dataBytes[2];
        _color = color;
        
        uint8_t size = dataBytes[3];
        _size =  size;
        
        NSString *macAddress = [NSString stringWithFormat:@"%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
                                dataBytes[9], dataBytes[8],
                                dataBytes[7],dataBytes[6],
                                dataBytes[5],dataBytes[4]];
        _bleMacAddress = macAddress;
        
        NSString *version = [NSString stringWithFormat:@"%x.%x.%x", dataBytes[10], dataBytes[11], dataBytes[12]];
        _softWareVersion = version;
        _needOemAuth = dataBytes[13] > 0; // 是否需要厂家认证
        // 充电模式
        _chargeType = dataBytes[14];
        // 主芯片型号
        _mainChip = dataBytes[15];
        //
        _generation = dataBytes[16];

        // functions
        uint8_t devFunctions = dataBytes[17];
        
        uint8_t supportExercise = devFunctions & 0x01; //是否支持运动模式
        _supportSportmode = supportExercise > 0;
        
        _supportECG = ((devFunctions >> 1)&0X01) > 0;
        
        _projectId = dataBytes[18] & 0XFF;
        
    }
    return self;
}


@end
